<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: qupen
  Date: 2016/9/18
  Time: 19:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="../include/head.jsp">
    <jsp:param name="title" value="邮件服务器配置"/>
</jsp:include>

<jsp:include page="../include/admin_header.jsp"/>

<jsp:include page="../include/admin_sidebar.jsp"/>

<div class="content-wrapper">
    <section class="content-header">
        <h4 class="page-title"><spring:message code="label.admin.set.mail.server"/></h4>
    </section>
    <section class="content">
        <div class="box box-primary">
            <div class="box-body">
                <div class="form-horizontal">
                    <div class="sie-padding-top">
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.admin.service.nameOrIp"/>:</label>

                            <div class="col-md-7">
                                <input id="ipAddress" class="form-control sie-input-border sie-input-uwh" value="${mailInfo.ip_address_key}"/>
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.tenant.children.name"/>:</label>

                            <div class="col-md-7">
                                <input id="userName" class="form-control sie-input-border sie-input-uwh" value="${mailInfo.username_key}"/>
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.login.password"/>:</label>

                            <div class="col-md-7">
                                <input id="password" type="password" class="form-control sie-input-border sie-input-uwh" value="${mailInfo.password_key}"/>
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.tenant.create.mail"/>:</label>

                            <div class="col-md-7">
                                <input id="mailAddress" class="form-control sie-input-border sie-input-uwh" value="${mailInfo.mailAddress_key}"/>
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.admin.mail.type"/>:</label>

                            <div class="col-md-7">
                                <select id="type" class="form-control sie-input-border sie-input-uwh"
                                        style="padding: 2px 12px;">
                                    <option value="smtp">SMTP</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.port"/>:</label>

                            <div class="col-md-7">
                                <input id="port" class="form-control sie-input-border sie-input-uwh" value="${mailInfo.port_key}"/>

                                <div style="margin-top: 80px">
                                    <a class="solid-button-gray" href="javascript:;" style="margin-right: 8px"><spring:message code="label.test"/></a>
                                    <a id="edit_button" class="solid-button-blue" href="javascript:;"><spring:message code="label.save"/></a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<jsp:include page="../include/foot.jsp"/>
<script>
    $(document).ready(function () {
        $("#edit_button").click(function () {
            var data = JSON.stringify({
                ip_address_key: $("#ipAddress").val(),
                username_key: $("#userName").val(),
                password_key: $("#password").val(),
                mailAddress_key: $("#mailAddress").val(),
                mailType_key: $("#type").find("option:selected").val(),
                port_key: $("#port").val()
            });
            $.ajax({
                type: "post",
                url: "/admin/api/v1/config/mail",
                data: {
                    mailConfig: data.toString()
                },
                success: function () {
                    swal({
                        title: '<spring:message code="label.create.success"/>',
                        text: "",
                        type: "success",
                        showCancelButton: false,
                        showConfirmButton: true,
                        confirmButtonText: '<spring:message code="label.admin.confirm"/>',
                        animation: "slide-from-top"
                    }, function () {
                         window.location.reload();
                    });
                },
                fail: function () {
                    swal("Error!", "", "error");
                }
            })
        })
    })
</script>
